<template>
  <div class="logs-data">
    <el-card :body-style="{ padding: '0px' }">
      <div slot="header">
        <tools-btn
          :toolsData="toolsData"
          @addData="addData"
          @refresh="refresh"
          @search="search"
          @fieldSet="fieldSet"
          @hasOperation="hasOperation"
        />
      </div>
      <table-list
        id="tableExcel"
        :table="table"
        ref="tableList"
        @handleEdit="handleEdit"
        @handleDel="handleDel"
      >
      </table-list>
      <pagination
        :page="page"
        @pageSizeChange="pageSizeChange"
        @pageCurrentChange="pageCurrentChange"
      />
    </el-card>

    <el-dialog
      :title="editDialog.title"
      v-if="editDialog.visible"
      :visible.sync="editDialog.visible"
      @close="closeDialog('editDialog')"
      width="30%"
    >
      <el-form
        :model="editDialog.data"
        ref="editDialog.data"
        label-width="90px"
      >
       <el-form-item label="设备编号">
          <el-input
            v-model="editDialog.data.id_IMEI"
            size="mini"
          />
        </el-form-item>
        <el-form-item label="设备名称">
          <el-input
            v-model="editDialog.data.deviceName"
            size="mini"
          />
        </el-form-item>
        <el-form-item label="地址">
          <el-input
            v-model="editDialog.data.location"
            size="mini"
          />
        </el-form-item>
        <el-form-item label="维修人姓名">
          <el-input
            v-model="editDialog.data.rname"
            size="mini"
          />
        </el-form-item>
        <el-form-item label="维修时间">
          <el-date-picker
            v-model="timeData"
            type="datetime"
            placeholder="选择维修时间"
            size="mini">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="上传文件">
          <el-upload
            class="upload-demo"
            action="http://61.181.255.77:18380/oilSmoke/uploadFile/uploadFile"
            multiple
            :on-success="fileSuccess"
            :limit="3"
            >
            <el-button size="mini" type="primary">点击上传</el-button>
          </el-upload>
        </el-form-item>
      </el-form>
      <span slot="footer">
        <el-button
          size="small"
          plain
          @click="closeDialog('editDialog')"
        >取 消</el-button>
        <el-popover
          class="edit-dialog-popover"
          placement="top"
          v-model="editDialog.submitVisible"
        >
          <p style="text-align: center; margin-top: 0; color:#409eff">
            确定提交吗？
          </p>
          <div style="text-align: center">
            <el-button
              size="mini"
              @click="editDialog.submitVisible = false"
              v-text="'取 消'"
              plain
            />
            <el-button
              type="primary"
              size="mini"
              v-text="'确 定'"
              v-if="showPrise"
              @click="handleSubmit"
              plain
              id="btn"
            />
            <el-button
              type="primary"
              size="mini"
              v-text="'确 定'"
              v-if="showRentPrise"
              @click="handleAdd"
              plain
            />
          </div>
          <el-button
            slot="reference"
            type="primary"
            size="small"
            v-text="'提 交'"
            plain
          />
        </el-popover>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import ToolsBtn from "../../components/Tools/ToolsBtn";
import TableList from "../../components/Table/TableList";
import TableProp from "../../utils/tableProps.js";
import Pagination from "../../components/Pagination/pagination";
import PageProp from "../../utils/pageProps.js";
import THead from "./HLogs.js"
export default {
  name: "Logs",
  data() {
    return {
      table: TableProp,
      page: PageProp,
      toolsData: {
        title: "用户管理",
        oBtnShow: [
          { btn0: false }, // 新增按钮
          { btn1: true }, // 刷新按钮
          { btn2: false }, // 搜索按钮
          { btn3: false }, // 设置按钮
          { btn4: false } // 导出Excel按钮
        ]
      },
      editDialog: {
        title: "编 辑",
        visible: false,
        submitVisible: false,
        data: null
      },
      showPrise: false,
      showRentPrise: false,
      imgUrl: '',
      timeData: ''
    };
  },
  components: {
    ToolsBtn,
    TableList,
    Pagination
  },
  created(){
    this.table.tHead = THead;
    this.table.hasOperation = false;
    this.table.identifier = true;
    this.table.operation.data = [
      {
        id: 1,
        label: "编 辑",
        Fun: "handleEdit",
        btnType: "text",
        plain: false,
        size: "mini",
        className: "handleEdit"
      }
    ];
    this.getList(1,50);
  },
  methods: {
    // 新增数据
    addData(){
      // console.log("新增数据")
      this.handleEdit();
    },
    // 刷新数据
    refresh(){
      // console.log("刷新数据")
      this.getList(1, 50);
    },
    // 搜索数据
    search(){
      // console.log("搜索数据")
    },
    // 设置字段
    fieldSet(){
      // console.log("设置字段")
    },
    // 隐藏表格操作列
    hasOperation(){
      // console.log("隐藏表格操作列");
      this.table.hasOperation = !this.table.hasOperation;
    },
    getList(pageNo, pageSize) {
      this.table.data = [];
      this.table.loading = true;
      const params = {
        pageNo,
        pageSize
      };
      // console.log(params)
      this.$api.RECORD.getData(params)
        .then(res => {
          const data = res.data;
          const total = res.count;
          this.table.data = data;
          this.page.total = total;
          this.table.loading = false;
        })
        .catch(() => {
          // console.log(err);
        });
    },
    // 分页大小
    pageSizeChange(size) {
      // console.log(`每页 ${size} 条`);
      const tableDataLength = this.table.data.length;
      this.page.pageSize = size;
      if (tableDataLength < this.page.pageSize) {
        this.getList(1, size);
      } else {
        const pageNo = this.page.currentPage;
        this.getList(pageNo, size);
      }
    },
    // 翻页
    pageCurrentChange(pageNo) {
      // console.log(`当前页: ${pageNo}`);
      this.page.currentPage = pageNo;
      const size = this.page.pageSize;
      this.getList(pageNo, size);
    },
    // 编辑模态框
    handleEdit(index, row){
      this.editDialog.visible = true
      if(index !== undefined && row !== undefined){
        this.showPrise = true;
        this.showRentPrise = false;
        const title = `${row.id_IMEI}编辑`;
        this.editDialog.title = title;
        const data = row;
        this.editDialog.data = data;
      } else {
        this.showRentPrise = true;
        this.showPrise = false;
        this.editDialog.title = "添加";
        this.editDialog.data = {};
      }
    },
    // 删除
    handleDel(){

    },
    closeDialog(name){
      if(name === "editDialog"){
        this[name].submitVisible = false;
        this[name].data = null;
      }
      this[name].visible = false;
    },
    // 图片上传成功
    fileSuccess(res){
       this.imgUrl = res.url
    }
  }
};
</script>

<style lang="scss" scoped>
/deep/ .el-dialog .el-dialog__title{
  font-size: 12px;
  
}
/deep/ .el-dialog .el-form-item__label{
    font-size: 12px;
}
.el-date-editor.el-input{
  width: 100%;
}
.el-table{
  padding-left: 20px;
}
</style>
